import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control

import * as filters from './filters' // global filters

// export const eventBus = new Vue()

if(process.env.NODE_ENV!='production') console.log('环境: ', process.env);

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.directive('strategy', {
  bind: (el) => {
    el.style.color = 'rgb(79, 149, 221)',
    el.style.cursor = 'pointer'
  },
  inserted: (el, params) => {
    el.addEventListener('click', () => {
      if(params.value.strategyType) {
        router.push({
          path: `/policyManage/netWorthAnalysis/${params.value.id}`,
          query: {
            // id: params.value.id,
            userId: params.value.userId,
            strategyType: params.value.strategyType,
            portfolioId: params.value.portfolioId,
          }
        })
      }else {
        router.push({
          path: `/policyManage/netWorthAnalysis/${params.value.id}`,
          query: {
            // id: params.value.id,
            userId: params.value.userId
          }
        })
      }
    })
  }
})

Vue.directive('afterStrategy', {
  bind: (el) => {
    // el.style.color = 'rgb(79, 149, 221)',
    el.style.color = 'rgb(50, 99, 180)',
    el.style.cursor = 'pointer'
  },
  inserted: (el, params) => {
    el.addEventListener('click', () => {
      router.push({
        path: '/afterManage/afterInvest/detailsPage/strategyAnalyse',
        query: {
          id: params.value.id,
          userId: params.value.userId,
          investId: params.value.investId,
        }
      })
    })
  }
})

// set tagsview title
Vue.prototype.$setTagsViewTitle = (tempRoute, title) => {
  const route = Object.assign({}, tempRoute, { title: title })
  store.dispatch('tagsView/updateVisitedView', route)
}

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})

